package cn.xopencode.oss.dal.mysql.mapper.permission;

import cn.xopencode.oss.dal.mysql.dataobject.permission.AdminPositionDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Repository
public interface AdminPositionMapper extends BaseMapper<AdminPositionDO> {

    default List<AdminPositionDO> selectByAdminId(String adminId) {
        return selectList(new QueryWrapper<AdminPositionDO>().eq("admin_id", adminId));
    }

    default List<AdminPositionDO> selectListByAdminId(String adminId) {
        return selectList(new QueryWrapper<AdminPositionDO>().eq("admin_id", adminId));
    }

    default List<AdminPositionDO> selectListByAdminIds(Collection<String> adminIds) {
        return selectList(new QueryWrapper<AdminPositionDO>().in("admin_id", adminIds));
    }

    default int deleteByAdminId(String adminId) {
        return delete(new QueryWrapper<AdminPositionDO>().eq("admin_id", adminId));
    }

    default int deleteByPositionId(String positionId) {
        return delete(new QueryWrapper<AdminPositionDO>().eq("position_id", positionId));
    }

    /**
     * 批量插入。因为 MyBaits Plus 的批量插入是基于 Service 实现，所以只好写 XML
     *
     * @param adminPositionDOS 数组
     */
    int insertList(@Param("adminPositionDOS") List<AdminPositionDO> adminPositionDOS);

}
